package com.ddwl.shop.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.schema.bo.shop.QueryShopCategoryBo;
import com.ddwl.shop.dao.mapper.ShopCategoryMapper;
import com.ddwl.shop.dao.model.ShopCategory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * (ShopCategory)表数据库访问层
 * @author wenbin
 */
@Slf4j
@Repository
public class ShopCategoryDao extends TkDao<ShopCategoryMapper, ShopCategory> {

    public List<ShopCategory> queryShopCategoryList(QueryShopCategoryBo bo) {
        Example example = getExample();
        example.and()
                .andEqualTo("effect",bo.getEffect())
                .andEqualTo("id",bo.getId())
                .andLike("shopCategoryName", MySqlUtil.allLike(bo.getCategoryName()))
                .andEqualTo("shopCategoryCode",bo.getCategoryCode())
                .andIn("shopCategoryCode",bo.getCategoryCodeList());
        return baseMapper.selectByExample(example);
    }

    public ShopCategory queryShopCategory(String id) {
        Example example = getExample();
        example.and()
                .andEqualTo("effect",1)
                .andEqualTo("id",id);
        return baseMapper.selectOneByExample(example);
    }

    public ShopCategory queryShopCategoryCode(String shopCategoryCode) {
        ShopCategory param = new ShopCategory();
        param.setShopCategoryCode(shopCategoryCode);
        return baseMapper.selectOne(param);
    }
}